import { DataTypes, Model } from 'sequelize'
import sequelize from './db'

export interface IKnowledgeBaseFile {
    id: number
    filename: string
    type: string
    url: string
    description: string
    status: string
    uploadTime: string
    knowledgeBaseId: number
}

class KnowledgeBaseFile extends Model {
    declare id: number
    declare filename: string
    declare type: string
    declare url: string
    declare description: string
    declare status: string
    declare uploadTime: string
    declare knowledgeBaseId: number
}

export enum KnowledgeBaseFileStatus {
    WaitEmbedding = 'WaitEmbedding',
    Embedding = 'Embedding',
    Embedded = 'Embedded',
    Failed = 'Failed',
}

KnowledgeBaseFile.init(
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        filename: {
            type: DataTypes.STRING,
            comment: '文件名',
        },
        type: {
            type: DataTypes.STRING,
            comment: '文件类型',
        },
        url: {
            type: DataTypes.STRING,
            comment: '文件地址',
        },
        description: {
            type: DataTypes.STRING,
            comment: '简介',
        },
        status: {
            type: DataTypes.STRING,
            comment: '状态，待向量化，向量化中，向量化完成',
        },
        metaData: {
            type: DataTypes.JSON,
            comment: '其他信息',
        },
        uploadTime: {
            type: DataTypes.DATE,
            comment: '发布时间',
        },
        knowledgeBaseId: {
            type: DataTypes.INTEGER,
            comment: 'knowledgeBaseId',
        },
    },
    {
        // 这是其他模型参数
        sequelize, // 我们需要传递连接实例
        modelName: 'knowledgebasefile', // 我们需要选择模型名称
        paranoid: true,
    }
)

export default KnowledgeBaseFile
